package com.tangjiali.setTopic1;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Test {
    public static void main(String[] args) {
        Set<String> names = new HashSet<>();
        names.add("刘备");
        names.add("关羽");
        names.add("张飞");
        names.add("刘备");
        names.add("张飞");

        System.out.println("集合大小：" + names.size());
        //使用迭代器遍历
        for (Iterator<String> iterator = names.iterator(); iterator.hasNext(); ) {
            System.out.println(iterator.next());
        }
        System.out.println("==============================================");
        //使用增强for
        for (String name : names) {
            System.out.println(name);
        }
    }
}
